package niu.toy.spring.support;



import java.util.Arrays;

/**
 * 属性名解析
 */
public class PropertyTokenHolder {
    public PropertyTokenHolder(String name) {
        this.actualName = name;
        this.canonicalName = name;
    }

    public String actualName;
    public String canonicalName;

    
    public String[] keys;

    @Override
    public String toString() {
        return "PropertyTokenHolder{" +
                "actualName='" + actualName + '\'' +
                ", canonicalName='" + canonicalName + '\'' +
                ", keys=" + Arrays.toString(keys) +
                '}';
    }
    public String parentPropertyPath(){
        if(keys!=null&&keys.length>=1){
            if(keys.length==1){
                return actualName;
            }else{//>=2
                StringBuilder indexedPropertyName = new StringBuilder(actualName);
                for (int i = 0; i < keys.length-1; i++) {
                    String key = keys[i];
                    indexedPropertyName.append(PropertyAccessor.PROPERTY_KEY_PREFIX).append(key).append(PropertyAccessor.PROPERTY_KEY_SUFFIX);
                }
                return indexedPropertyName.toString();
            }
        }
        return null;
    }
}